﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellStorageFactory_h
#define CellStorageFactory_h

#include "CellPrerequisites.h"

namespace cell
{
/** \addtogroup Core
 *  @{
 */
/** \addtogroup General
 *  @{
 */

/// Bitmask containing storage types
typedef uint16 StorageTypeMask;

enum StorageType
{
	/// 文件存储器。
	ST_SINGLE_FILE,

	/// 基于 SQLite 的存储器。
	ST_SQLITE
};

struct StorageMetaData
{
	/// 标识存储器类型的唯一字符串标识符。
	String typeName;
	/// 存储器文本描述。
	String description;
	/// 类型掩码。
	StorageTypeMask storageTypeMask;
};

/** 存储器工厂。
@author
	Jiangwei Xu
*/
class _CellExport StorageFactory : public StorageAlloc
{
public:
	/**
	*/
	StorageFactory(void);

	/**
	*/
	virtual ~StorageFactory(void);

public:
	/**
	*/
	virtual const StorageMetaData& getMetaData(void) const;

public:
	/**
	*/
	virtual Storage* createInstance(const String& instanceName) = 0;

	/**
	*/
	virtual void destroyInstance(Storage* instance) = 0;

protected:
	/// Internal method to initialise the metadata, must be implemented
	virtual void initMetaData(void) const = 0;

protected:
	mutable StorageMetaData mMetaData;
	mutable bool mMetaDataInit;
};

/** @} */
/** @} */
} // end namespace cell

#endif // CellStorageFactory_h
